(load "dabbrev-ja")
(require 'auto-install)
(require 'anything-config)
(require 'anything-etags)
(require 'autoinsert)
(require 'cl)
(require 'erlang-start)
(autoload 'moz-minor-mode "moz" "Mozilla Minor and Inferior Mozilla Modes" t)

(setq inhibit-startup-message t)
(setq transient-mark-mode t)
(setq-default show-trailling-whitespace t)
(setq-default tab-width 2 indent-tabs-mode nil)
(setq-default fill-column 79)

(show-paren-mode t)
(delete-selection-mode 1)

(progn
  (set-language-environment "Japanese")
  (set-terminal-coding-system 'utf-8)
  (set-keyboard-coding-system 'utf-8)
  (set-buffer-file-coding-system 'utf-8)
  (setq default-buffer-file-coding-system 'utf-8)
  (set-default-coding-systems 'utf-8))

(add-hook 'shell-mode-hook (function
			    (lambda () (set-buffer-process-coding-system 'utf-8 'utf-8))))
(add-hook 'before-save-hook 'time-stamp)
(add-hook 'find-file-hooks 'auto-insert)

(auto-install-update-emacswiki-package-name t)

(global-set-key "\C-h" 'delete-backward-char)
(global-set-key "\C-o" 'dabbrev-expand)
(global-set-key (kbd "C-;") 'anything)

(setq anything-sources (list anything-c-source-buffers
                             anything-c-source-bookmarks
                             ;anything-c-source-recentf
                             anything-c-source-file-name-history
                             anything-c-source-locate
                             ))
(anything-iswitchb-setup)
(setq anything-etags-enable-tag-file-dir-cache t)
(setq anything-etags-cache-tag-file-dir "~/.emacs.d/")


(setq process-coding-system-alist
      (cons '("gosh" utf-8 . utf-8) process-coding-system-alist))
(autoload 'inferior-gauche-mode "inferior-gauche" nil t)
(add-to-list 'auto-mode-alist (cons  "\\.\\(scm\\)\\'" 'inferior-gauche-mode))
;;inferior-gauche.el内の設定も見ること。
;;(defvar igosh-decoding-system 'utf-8)
;;(defvar igosh-encoding-system 'utf-8)

(autoload 'js2-mode "js2" nil t)
(add-to-list 'auto-mode-alist '("\\.jsm?$" . js2-mode))
(add-hook 'js2-mode-hook (lambda () (moz-minor-mode 1)))

;; cperl-mode の設定。インデントをいい感じに、他。
(autoload 'cperl-mode "cperl-mode" "alternate mode for editing Perl programs" t)
(add-to-list 'auto-mode-alist '("\\.\\([pP][Llm]\\|al\\)\\'" . cperl-mode))
(add-to-list 'interpreter-mode-alist '("perl" . cperl-mode))
(add-to-list 'interpreter-mode-alist '("perl5" . cperl-mode))
(add-to-list 'interpreter-mode-alist '("miniperl" . cperl-mode))
(setq cperl-auto-newline nil)
(setq cperl-indent-parens-as-block t)
(setq cperl-close-paren-offset -4)
(setq cperl-indent-level 4)
(setq cperl-label-offset -4)
(setq cperl-continued-statement-offset 4)
(setq cperl-highlight-variables-indiscriminately t)
(add-hook 'cperl-mode-hook
          (lambda ()
            (set-face-italic-p 'cperl-hash-face nil)))
(add-hook 'cperl-mode-hook
	  '(lambda ()
	     (define-key cperl-mode-map "\C-cc" 'cperl-check-syntax)
	     (setq indent-tabs-mode nil)))

(custom-set-variables
  ;; custom-set-variables was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(js2-mirror-mode nil)
 '(js2-mode-escape-quotes nil))
(custom-set-faces
  ;; custom-set-faces was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 )

(setq user-fll-name "Teruaki Gemma")
(setq user-mail-address "teruakigemma@gmail.com")
(setq auto-insert-directory "/home/teruaki/.emacs.d/templates/")
(setq auto-insert-alist
      (append '(("\\.hs$" . ["template.hs" my-template])
		("\\.c$"   . ["template.c"  my-template])
		("\\.h$"   . ["template.h"  my-template])
		("\\.stub$". ["template.stub"  my-template])
		("\\.scm$" . ["template.scm"
			     (lambda() (my-template-exec "/usr/local/bin/gosh"))
			     my-template])
		("\\.sh$" . ["template.sh"
			     (lambda() (my-template-exec "/bin/sh"))
			     my-template])
		("\\.py$" . ["template.sh"
			     (lambda() (my-template-exec "/usr/bin/python"))
			     my-template])
		("\\.rb$" . ["template.rb"
			     (lambda() (my-template-exec "/usr/bin/ruby"))
			     my-template]))
		auto-insert-alist))

(defvar template-replacements-alists
  '(("%file%" . (lambda()(file-name-nondirectory (buffer-file-name))))
    ("%name%" . user-full-name)
    ("%mail%" . (lambda()(identity user-mail-address)))
    ("%cyear%" . (lambda()(substring (current-time-string) -4)))
    ("%bdesc%" . (lambda()(read-from-minibuffer "Brief description: ")))))

(defun my-file-body-name (file-name)
  (substring file-name 0 (position 46 file-name)))

(defmacro defreplace (name replace-string)
  `(defun ,name (str)
     (goto-char (point-min))
     (replace-string ,replace-string str)))

(defreplace my-template-exec    "%exec%")
(defreplace my-template-package "%package%")

(defun my-template ()
  (time-stamp)
  (mapc #'(lambda(c)
	    (progn
	      (goto-char (point-min))
	      (replace-string (car c) (funcall (cdr c)) nil)))
	template-replacements-alists)
  (goto-char (point-max))
  (message "done."))

